package com.example.pclimb.dao;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.example.pclimb.model.Review;

import java.util.List;

/**
 * 评价数据访问接口
 */
@Dao
public interface ReviewDao {
    @Insert
    long insert(Review review);

    @Update
    void update(Review review);

    @Delete
    void delete(Review review);

    @Query("SELECT * FROM reviews WHERE id = :id")
    LiveData<Review> getReviewById(int id);

    @Query("SELECT * FROM reviews WHERE userId = :userId")
    LiveData<List<Review>> getReviewsByUserId(int userId);

    @Query("SELECT * FROM reviews WHERE guideId = :guideId")
    LiveData<List<Review>> getReviewsByGuideId(int guideId);

    @Query("SELECT * FROM reviews WHERE requestId = :requestId")
    LiveData<Review> getReviewByRequestId(int requestId);

    @Query("SELECT AVG(rating) FROM reviews WHERE guideId = :guideId")
    LiveData<Float> getAverageRatingForGuide(int guideId);

    @Query("SELECT COUNT(*) FROM reviews WHERE guideId = :guideId")
    LiveData<Integer> getReviewCountForGuide(int guideId);
} 